#include "StdAfx.h"
#include "ResourceManager.h"
#include "Marco.h"
#include "Globals.h"

ResourceManager* ResourceManager::instance=NULL;
ResourceManager::ResourceManager(void)
{
	textureShader = new Shaders();
	triangleShader = new Shaders();
	textShader = new Shaders();
	terrainShader = new Shaders();

	//Skybox initialize data include
	m_skbShader = new Shaders();
	m_skbTexture = new Texture();
	m_skbModel = new Model();
}

ResourceManager::~ResourceManager(void)
{
	Delete(textureShader);
	Delete(triangleShader);
	Delete(terrainShader);
	//Delete(hcn);
	//Delete(buttonBackGround);
	//Delete(menuBackGround);
	Delete(textShader);

	Delete(m_skbShader);
	Delete(m_skbModel);
	Delete(m_skbTexture);
}

void ResourceManager::Load()
{
	
}


int ResourceManager::Load(ESContext* esContext)
{
	int err = 0;
	err = err*textureShader->Init("../Resources/Shaders/TriangleShaderVS.vs", "../Resources/Shaders/TriangleShaderFS.fs");
	err = err*triangleShader->Init("../Resources/Shaders/TextureVertexShader.vsh", "../Resources/Shaders/TextureFragmentShader.fsh");
	err = err*textShader->Init("../Resources/Shaders/Text.vsh", "../Resources/Shaders/Text.fsh");
	err = err*terrainShader->Init("../Resources/Shaders/terrainVS.vs", "../Resources/Shaders/terrainFS.fs");
	/*Vertex* vertexData = new Vertex[4];
	vertexData[0].position = Vector3(0.0f, 0.0f, 0.0f);
	vertexData[0].texcoord = Vector2(0.0f, 0.0f);
	vertexData[1].position = Vector3(0.0f, 1.0f, 0.0f);
	vertexData[1].texcoord = Vector2(0.0f, 1.0f);
	vertexData[2].position = Vector3(1.0f, 1.0f, 0.0f);
	vertexData[2].texcoord = Vector2(1.0f, 1.0f);
	vertexData[3].position = Vector3(1.0f, 0.0f, 0.0f);
	vertexData[3].texcoord = Vector2(1.0f, 0.0f);

	hcn = new Model();
	hcn->SetVertices(vertexData, 4);
	delete vertexData;*/

	//GLushort indices[6] = { 0, 1, 2,0,2,3 };
	//hcn->SetIndices(indices, 6);


	//buttonBackGround = new Texture();
	//menuBackGround = new Texture();
	//char* path = "..\\Resources\\Textures\\Rock.tga";
	//buttonBackGround->Load2DTexture(path);
	//path = "..\\Resources\\Textures\\menuBackGround.tga";
	//menuBackGround->Load2DTexture(path);


	////Skybox init
	//m_skbShader->Init("../Resources/Shaders/skydomeShaderVS.vs", "../Resources/Shaders/skydomeShaderFS.fs");
	//char **skbPath = new char*[6];
	//skbPath[0] = "../Resources/Textures/Skydome_0.tga";
	//skbPath[1] = "../Resources/Textures/Skydome_1.tga";
	//skbPath[2] = "../Resources/Textures/Skydome_2.tga";
	//skbPath[3] = "../Resources/Textures/Skydome_3.tga";
	//skbPath[4] = "../Resources/Textures/Skydome_4.tga";
	//skbPath[5] = "../Resources/Textures/Skydome_5.tga";
	//m_skbTexture->InitTextureCube(skbPath);
	//m_skbModel->Load("../Resources/Models/Skybox.nfg");
	//Delete_Array(skbPath);

	return err;
}

ResourceManager* ResourceManager::GetInstance()
{
	if (instance!=NULL)
		return instance;
	instance=new ResourceManager();
	return instance;
}